/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hoja.de.trabajo.pkg5;

/**
 *
 * @author RAUL
 */
public class ListaCircular<E> extends AbstractCola<E> {
    protected Node<E> cola; 
    boolean resultado; 
    
    protected int count;
    public ListaCircular()
    // pre: constructs a new circular list
    {
    cola = null;
    count = 0;
    }

public void addFirst(E value)
// pre: value non-null
// post: adds element to head of list
{
    Node<E> temp = new Node<E>(value);
        if (cola == null) { // first value added
            cola = temp;
            cola.setNext(cola);
            } else { // element exists in list
                temp.setNext(cola.next());
                cola.setNext(temp);
    }
    count++;
    }
    public void addLast(E value)
    // pre: value non-null
    // post: adds element to tail of list
    {
    // new entry:
    addFirst(value);
    cola = cola.next();
    }
    public E remove()
    // pre: !isEmpty()
    // post: returns and removes value from tail of list
    {

    Node<E> cola1 = cola;
    while (cola1.next() != cola) {
    cola1 = cola1.next();
    }
    // cola1 now points to second-to-last value
    Node<E> temp = cola;
    if (cola1 == cola)
    {
    cola = null;
    } else {
    cola1.setNext(cola.next());
    cola = cola1;
    }
    count--;
    return temp.value();
    }

    @Override
    public int size() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean offer(E e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public E poll() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public E peek() {
        throw new UnsupportedOperationException("Not supported yet.");
    }


}
